package com.midea.ai.air.ui.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.ui.home.data.SceneModel;

import java.util.List;

/**
 * Created by ouyangdi on 2016/4/8.
 * 情景ListView对应的Adapter
 */
public class EditRoomSceneAdapter extends ArrayAdapter<SceneModel> {
    private LayoutInflater mInflater;

    public EditRoomSceneAdapter(Context context, int resource, List<SceneModel> objects) {
        super(context, resource, objects);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        SceneModel item = getItem(position);
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.item_edit_room_scene_list, parent, false);
            holder = new ViewHolder();
            holder.ivIcon = (ImageView)convertView.findViewById(R.id.iv_icon);
            holder.tvScene = (TextView)convertView.findViewById(R.id.tv_device);
            holder.tvParams = (TextView)convertView.findViewById(R.id.tv_detail);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.ivIcon.setImageResource(item.getResIdIcon());
        holder.tvScene.setText(item.getStrScene());
        holder.tvParams.setText(item.getStrParas());
        return convertView;
    }

    private class ViewHolder {
        ImageView ivIcon;
        TextView tvScene;
        TextView tvParams;
    }
}
